package com.dianxin.farm.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dianxin.farm.entity.CustomerBalance;
import com.dianxin.farm.entity.CustomerInfo;
import com.dianxin.farm.entity.EnterpriseInfo;
import com.dianxin.farm.entity.pojo.CustomerInfoResponse;
import com.dianxin.farm.filter.AuthorCheck;
import com.dianxin.farm.mapper.customer.CustomerBalanceMapper;
import com.dianxin.farm.mapper.customer.CustomerInfoMapper;
import com.dianxin.farm.mapper.customer.EnterpriseInfoMapper;

import com.dianxin.farm.request.account.QueryCustomerPageRequest;
import com.dianxin.farm.request.common.IdPageRequest;
import com.dianxin.farm.request.common.IdRequest;
import com.dianxin.farm.service.CurrentLoginService;

import com.dianxin.farm.util.web.ApiResponse;
import com.dianxin.farm.util.web.ApiResponseUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 橱窗信息表 前端控制器
 * </p>
 *
 * @author xukai
 * @since 2020-09-14
 */
@RestController
@RequestMapping(value = "/customerInfo", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@AuthorCheck
@Api(description = "管理端用户信息控制器")
public class CustomerInfoController {

    @Resource
    private CustomerBalanceMapper customerBalanceMapper;
    @Resource
    private EnterpriseInfoMapper enterpriseInfoMapper;
    @Resource
    private CurrentLoginService currentLoginService;
    @Resource
    private CustomerInfoMapper customerInfoMapper;

    @ApiOperation("查看会员列表信息，返回用户基本信息以及账户余额")
    @RequestMapping(value = "/customerPage")
    @ResponseBody
    @AuthorCheck
    public ApiResponse<PageInfo<CustomerInfoResponse>> customerPage(@RequestBody QueryCustomerPageRequest request) {
        PageHelper.startPage(request.getPage(), request.getSize());
        List<CustomerInfoResponse> list = customerInfoMapper.selectByCondition(request.getCustomerName(), request.getPhone(),request.getRole());
        return ApiResponseUtils.success(new PageInfo<>(list));
    }


    @ApiOperation("查看原始股东下的会员列表")
    @RequestMapping(value = "/sonCustomerPage")
    @ResponseBody
    @AuthorCheck
    public ApiResponse<PageInfo<CustomerInfo>> customerPage(@RequestBody IdPageRequest request) {
        PageHelper.startPage(request.getPage(), request.getSize());
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_id",request.getId());
        List<CustomerInfo> list = customerInfoMapper.selectList(wrapper);
        return ApiResponseUtils.success(new PageInfo<>(list));
    }




}
